//
//  KASatisfactionViewController.m
//  KeepAccounts
//
//  Created by honeyrr on 2017/10/30.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "KASatisfactionViewController.h"

@interface KASatisfactionViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *myTableView;

@property (nonatomic,strong) NSArray *arr;
//标记选中的那一行
@property (nonatomic,weak) NSIndexPath *indexPath;


@end

@implementation KASatisfactionViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"满意度调查";
    _myTableView.rowHeight = 50;
    _myTableView.tableFooterView = [UIView new];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStyleDone target:self action:@selector(commitResult)];
    
    NSString *str = @"";
    NSMutableArray *marr = [NSMutableArray array];
    for (int i = 10; i >= 0; i--) {
        if (i == 10) {
            str = [NSString stringWithFormat:@"%d分 (非常愿意)",i];
        } else if (i == 0) {
            str = [NSString stringWithFormat:@"%d分 (绝对不会)",i];
        } else {
            str = [NSString stringWithFormat:@"%d分",i];
        }
        [marr addObject:str];
    }
    _arr = marr;
    
    [self.myTableView setEditing:YES animated:YES];
}

-(void)commitResult
{
    if (_indexPath) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"提交成功，非常感谢您的反馈" preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:[UIAlertAction actionWithTitle:@"关闭" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
        }]];
        [self presentViewController:alert animated:YES completion:nil];
    }
}



//cell的编辑样式
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _arr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *ID = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
    }
    cell.textLabel.text = _arr[indexPath.row];
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    _indexPath = indexPath;
    [_myTableView reloadData];
    [_myTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"您在多大程度上愿意向您的朋友推荐此APP？";
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 48;
}

@end
